package com.zhijian.warehouse.manage.controller.app;

import com.zhijian.response.annotation.Response;
import com.zhijian.util.page.Page;
import com.zhijian.warehouse.manage.entity.vo.request.WarehouseSearchVo;
import com.zhijian.warehouse.manage.entity.vo.response.WarehouseVo;
import com.zhijian.warehouse.manage.enums.DelFlagEnum;
import com.zhijian.warehouse.manage.service.WarehouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 仓库 控制层
 *
 * @author auto
 * @version 1.0
 * @date 2024-10-10 19:10:55
 */
@Slf4j
@Controller
@Api(tags = "app仓库")
@RequestMapping("/app")
public class AppWarehouseController {
    
    @Autowired
    private WarehouseService service;
    
    
    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Response
    @GetMapping("/warehouse/{id}")
    @ApiOperation("根据id查询")
    public WarehouseVo selectById(@PathVariable("id") Long id) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), id);
        return service.selectVoById(id);
    }
    
    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/warehouse/page")
    @ApiOperation("分页查询")
    public Page<WarehouseVo> selectByCondition(@RequestBody(required = false) WarehouseSearchVo param) {
        if (param == null)
            param = WarehouseSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        param.setIsDelete(DelFlagEnum.USING.value);
        return service.selectPage(param);
    }
    
    /**
     * 列表查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/warehouse/list")
    @ApiOperation("列表查询")
    public List<WarehouseVo> selectList(@RequestBody(required = false) WarehouseSearchVo param) {
        if (param == null)
            param = WarehouseSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        param.setIsDelete(DelFlagEnum.USING.value);
        return service.selectList(param);
    }
    
    
    /**
     * 修改状态
     *
     * @param id
     * @param status
     */
    @Response
    @PutMapping("/warehouse/status/{id}/{status}")
    @ApiOperation("修改状态")
    public void changeStatus(
            @ApiParam(name = "id", value = "主键ID", required = true) @PathVariable("id") Long id,
            @ApiParam(name = "status", value = "开关值，1：启用，0：停用", required = true) @PathVariable("status") Byte status) {
        service.changeStatus(id, status);
    }
}
